package com.xinggq.pay.service.config;

import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * RestTemplate配置类
 * @author xinggq
 * @since 2025/9/16
 */
@Configuration
@EnableScheduling
public class ResttemplateConfig {

    /**
     * 回调专用的RestTemplate
     */
    @Bean("callbackRestTemplate")
    public RestTemplate callbackRestTemplate(RestTemplateBuilder builder) {
        return builder
            .connectTimeout(Duration.ofSeconds(5))
            .readTimeout(Duration.ofSeconds(10))
            .additionalRequestCustomizers(request -> {
                request.getHeaders().add("Connection", "close");
            })
            .build();
    }
}